﻿using System;
using System.Web.UI;

namespace MikeKappel.Com.CS
{
    public static partial class Javascript
    {
        public static void AddOnLoad(Page CurrentPage, String script)
        {
            ScriptManager CurrentScriptManager = ScriptManager.GetCurrent(CurrentPage);
            if ((CurrentScriptManager != null && ((ScriptManager)CurrentScriptManager).IsInAsyncPostBack))
            {
                ScriptManager.RegisterClientScriptBlock(CurrentPage, CurrentPage.GetType(), Guid.NewGuid().ToString(), script + "\n", true);
            }
            else
            {
                CurrentPage.Page.ClientScript.RegisterStartupScript(CurrentPage.GetType(), Guid.NewGuid().ToString(), script + "\n", true);
            }
        }
    }
}